1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
"use client"
import * as React from "react"
import { Button } from "@/components/ui/button"
import { Badge } from "@/components/ui/badge"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
import { Textarea } from "@/components/ui/textarea"
import { ChevronLeft } from "lucide-react"
import Link from "next/link"
import { toast } from "sonner"
import { saveVendorComment, acceptContract, rejectContract } from "@/lib/po/vendor-table/service"
import { useRouter } from "next/navigation"
import { ContractInfoCard } from "@/components/contract/contract-info-card"
import { ContractItemsCard } from "@/components/contract/contract-items-card"
interface ContractDetailClientProps {
contract: any
lng: string
}
export function ContractDetailClient({ contract, lng }: ContractDetailClientProps) {
const router = useRouter()
const [vendorComment, setVendorComment] = React.useState(contract.vendorComment || "")
const [isLoading, setIsLoading] = React.useState(false)
const [isRejectDialogOpen, setIsRejectDialogOpen] = React.useState(false)
const [rejectReason, setRejectReason] = React.useState("")
const handleSaveComment = async () => {
try {
setIsLoading(true)
const result = await saveVendorComment(contract.id, vendorComment)
if (result.success) {
toast.success(result.message)
router.refresh()
} else {
toast.error("의견 저장에 실패했습니다.")
}
} catch {
toast.error("의견 저장 중 오류가 발생했습니다.")
} finally {
setIsLoading(false)
}
}
const handleApprove = async () => {
try {
setIsLoading(true)
const result = await acceptContract(contract.id)
if (result.success) {
toast.success(result.message)
router.refresh()
} else {
toast.error("계약 승인에 실패했습니다.")
}
} catch {
toast.error("계약 승인 중 오류가 발생했습니다.")
} finally {
setIsLoading(false)
}
}
const handleRejectClick = () => {
setIsRejectDialogOpen(true)
}
const handleRejectConfirm = async () => {
if (!rejectReason.trim()) {
toast.error("계약 반려 사유를 입력해주세요.")
return
}
try {
setIsLoading(true)
const result = await rejectContract(contract.id, rejectReason)
if (result.success) {
toast.success(result.message)
setIsRejectDialogOpen(false)
setRejectReason("")
router.refresh()
} else {
toast.error("계약 거절에 실패했습니다.")
}
} catch {
toast.error("계약 거절 중 오류가 발생했습니다.")
} finally {
setIsLoading(false)
}
}
const handleRejectCancel = () => {
setIsRejectDialogOpen(false)
setRejectReason("")
}
return (
<>
{/* 헤더 */}
<div className="flex items-center justify-between">
<div className="flex items-center gap-4">
<Link href={`/${lng}/partners/po`}>
<Button variant="ghost" size="icon">
<ChevronLeft className="h-5 w-5" />
</Button>
</Link>
<div className="flex items-center gap-3">
<h1 className="text-2xl font-bold tracking-tight">계약 상세</h1>
<div className="flex items-center gap-2">
<span className="text-sm text-muted-foreground">계약번호:</span>
<span className="text-sm font-medium">{contract.contractNo}</span>
<Badge variant="outline" className="ml-2">
{contract.status}
</Badge>
</div>
</div>
</div>
<div className="flex gap-2">
<Button
variant="outline"
onClick={handleSaveComment}
disabled={isLoading}
>
의견저장
</Button>
<Button
variant="default"
onClick={handleApprove}
disabled={isLoading}
>
계약승인
</Button>
<Button
variant="destructive"
onClick={handleRejectClick}
disabled={isLoading}
>
계약반려
</Button>
</div>
</div>
{/* 계약 조건 */}
<ContractInfoCard contract={contract} />
{/* 코멘트 */}
<Card>
<CardHeader>
<CardTitle className="text-lg">코멘트</CardTitle>
</CardHeader>
<CardContent>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="space-y-2">
<label htmlFor="vendor-comment" className="text-sm font-medium">
Vendor Comment
</label>
<textarea
id="vendor-comment"
className="w-full min-h-[100px] px-3 py-2 text-sm border rounded-md resize-none focus:outline-none focus:ring-2 focus:ring-ring"
placeholder="벤더 코멘트를 입력하세요..."
value={vendorComment}
onChange={(e) => setVendorComment(e.target.value)}
/>
</div>
<div className="space-y-2">
<label htmlFor="shi-comment" className="text-sm font-medium text-muted-foreground">
SHI Comment
</label>
<div className="w-full min-h-[100px] px-3 py-2 text-sm border rounded-md bg-muted/50">
{contract.shiComment || "코멘트가 없습니다."}
</div>
</div>
</div>
</CardContent>
</Card>
{/* 계약문서 */}
<Card>
<CardHeader>
<CardTitle className="text-lg">계약문서</CardTitle>
</CardHeader>
<CardContent>
{contract.contractContent ? (
<div className="prose prose-sm max-w-none">
<pre className="whitespace-pre-wrap text-sm bg-muted/50 p-4 rounded-md">
{contract.contractContent}
</pre>
</div>
) : (
<p className="text-sm text-muted-foreground">계약문서 내용이 없습니다.</p>
)}
</CardContent>
</Card>
{/* 계약 품목 */}
<ContractItemsCard items={contract.items || []} currency={contract.currency} />
{/* 계약 반려 다이얼로그 */}
<Dialog open={isRejectDialogOpen} onOpenChange={setIsRejectDialogOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>계약 반려</DialogTitle>
<DialogDescription>
계약을 반려하는 사유를 입력해주세요. 이 정보는 SHI 담당자에게 전달됩니다.
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="space-y-2">
<label htmlFor="reject-reason" className="text-sm font-medium">
반려 사유 <span className="text-destructive">*</span>
</label>
<Textarea
id="reject-reason"
placeholder="계약 반려 사유를 입력해주세요..."
value={rejectReason}
onChange={(e) => setRejectReason(e.target.value)}
rows={5}
className="resize-none"
/>
</div>
</div>
<DialogFooter>
<Button
variant="outline"
onClick={handleRejectCancel}
disabled={isLoading}
>
취소
</Button>
<Button
variant="destructive"
onClick={handleRejectConfirm}
disabled={isLoading || !rejectReason.trim()}
>
{isLoading ? "처리 중..." : "반려 확정"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</>
)
}
|